home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Think Class Libraries / CMIDI 2.2 / CMIDIDataPort.cp < prev    next >
Encoding:
Text File  |  1994-11-30  |  4.2 KB  |  128 lines  |  [TEXT/KAHL]

  1. /*
  2.  *——— CMIDIDataPort.cp —————————————————————————————————————————————————————————————————
  3.  * Copyright © Paul Ferguson, 1990-94.  All rights reserved.
  4.  *
  5.  * Superclass:  CMIDIPort
  6.  * Subclasses:  CInputPort
  7.  *                COutputPort
  8.  *
  9.  * Description:
  10.  *    CMIDIDataPort.c defines a MIDI Manager port object.  CMIDIDataPort is an abstract
  11.  *    type, containing variables and methods common to input and output port types.
  12.  *
  13.  *    For use with Symantec C++ 6.0, the accompanying THINK Class Library (TCL), and MIDI
  14.  *    Manager 2.0. Refer to the accompanying Microsoft Word document for complete
  15.  *    details about MIDI Manager objects.
  16.  *
  17.  *    If you have comments or questions about this code, you can reach me on
  18.  *    CompuServe at 70441,3055.
  19.  *
  20.  *——————————————————————————————————————————————————————————————————————————————————————
  21.  *———— NOTE ——— NOTE ——— NOTE ——— NOTE ——— NOTE ——— NOTE ——— NOTE ——— NOTE ——— NOTE ————
  22.  *——————————————————————————————————————————————————————————————————————————————————————
  23.  *    If you are not familiar with programming the Apple MIDI Manager, refer to the
  24.  *    "MIDI Management Tools" Version 2.0, available from APDA.  You MUST have the
  25.  *    software (MIDI.H and the library) from this package in order to use these objects.
  26.  *    It will not work without this.
  27.  *——————————————————————————————————————————————————————————————————————————————————————
  28.  *    REVISION HISTORY:
  29.  *        August ??, 1990            - Original release (1.0).
  30.  *        November 5, 1990        - Added checks for midiMgrVer to most methods.
  31.  *        August 1991                - updated for THINK C 5.0 as version 2.0
  32.  *        July 1993                - updated for Symantec C++ 6.0.
  33.  *——————————————————————————————————————————————————————————————————————————————————————
  34.  */
  35.  
  36. #include "CMIDIDataPort.h"                    // This code's header file
  37.  
  38. extern    OSType            gSignature;            // Used to register client
  39. extern CMIDIClient *     gMIDIClient;
  40.  
  41. /*
  42.  *——— NOTE ————————————————————————————————————————————————————————
  43.  * Note that there is no initialization method for this class.
  44.  * The subclasses CMIDIInputPort and CMIDIOutputPort initialization
  45.  * methods call IMIDIPort() directly.  There is not really any
  46.  * need for an initializer here.
  47.  *—————————————————————————————————————————————————————————————————
  48.  */
  49.  
  50.  
  51. /*
  52.  *——— CMIDIDataPort::LoadPatches ——————————————————————————————————
  53.  * Read in patch information from a specified resource. This may
  54.  * also return resNotFound error, which should be handled by the
  55.  * application.
  56.  *—————————————————————————————————————————————————————————————————
  57.  */
  58.  
  59. OSErr CMIDIDataPort::LoadPatches(ResType theResType, short theResID)
  60. {
  61.     MIDIPortInfoHdl    rsrcPortInfoH, ourPortInfoH;
  62.     short            i;
  63.     OSErr            theErr = noErr;
  64.  
  65.     if ( ! itsVersion )
  66.         return ErrNoMIDI;
  67.  
  68.     ourPortInfoH = GetPortInfo();
  69.     
  70.     switch (itsResult)        // This was set during initialization
  71.     {
  72.     case midiVConnectMade:
  73.         if ((**ourPortInfoH).numConnects > 0)
  74.             break;
  75.                                     // else fall through to next case...
  76.                                     // (only have a time base connection)
  77.         itsResult = noErr;            //  cheat a little bit, and ... FALL THROUGH!
  78.     case noErr:
  79.     
  80.         // Check for virtual connections stored in the specified resource.
  81.  
  82.         rsrcPortInfoH = (MIDIPortInfoHdl) GetResource(theResType, theResID);
  83.         if ( rsrcPortInfoH == (MIDIPortInfoHdl) 0 )
  84.             return resNotFound;
  85.  
  86.         // Lock resource and call MIDIConnectData
  87.  
  88.         HLock((Handle) rsrcPortInfoH);
  89.         if ((**ourPortInfoH).type == (**rsrcPortInfoH).type)
  90.         {
  91.             for (i = 0; i < (**rsrcPortInfoH).numConnects; i++)
  92.             {
  93.                 theErr = MIDIConnectData(gSignature,
  94.                             itsPortID,
  95.                             (**rsrcPortInfoH).cList[i].clientID,
  96.                             (**rsrcPortInfoH).cList[i].portID);
  97.             }
  98.         }
  99.         HUnlock((Handle) rsrcPortInfoH);
  100.         ReleaseResource((Handle) rsrcPortInfoH);
  101.         break;
  102.     default:                        // Not likely to see this case
  103.         break;
  104.     }
  105.     return theErr;
  106. }
  107.  
  108.  
  109. /*
  110.  *——— CMIDIDataPort::Get/SetTCFormat —————————————————————————————
  111.  * Retrieve or set the time code format.  Constants for valid
  112.  * formats are in MIDI.h
  113.  *————————————————————————————————————————————————————————————————
  114.  */
  115.  
  116. short CMIDIDataPort::GetTCFormat(void)
  117. {
  118.     return (itsVersion ? MIDIGetTCFormat(itsRefNum) : -1);
  119. }
  120.  
  121. void CMIDIDataPort::SetTCFormat(short theFormat)
  122. {
  123.     if (itsVersion)
  124.         MIDISetTCFormat(itsRefNum, theFormat);
  125. }
  126.  
  127. // end of CMIDIDataPort.cp
  128.